package cn.edu.zbu.utils;

import java.sql.*;

public class JDBCUtils {
    public static Connection getConnection() throws Exception {
        Connection conn = null;
        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");
//            String url="jdbc:mysql://localhost:3306/jk5";
        String url = "jdbc:mysql:///jk5";
        String username = "root";
        String password = "182728";
        conn = DriverManager.getConnection(url, username, password);
        return conn;
    }

    public static void close(ResultSet rs, Statement stmt, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
